#include<bits/stdc++.h>
using namespace std;
long long n,sz[2000500],b[2000500],len=0,cnt=0,x[2000100],zh;
int ans[2000200];
vector<int> c[2000500];
vector< pair< long long,pair<long long,long long> > > temp;
unordered_map<int,int> tong;
vector<int> era1[2001000];
vector< pair<int,int> > era2[2001000];
pair<long long,long long> res[2001000];
int fd(int nw) {return lower_bound(ans+1,ans+ans[0]+1,nw)-ans;}
main()
{
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	long long nw=0,sum1=0,sum2=0,sum3=0;
	for(long long i=1;i<=n;i++)
	{
		cin>>sz[i],sum3+=sz[i]-1;
		for(long long j=1;j<=sz[i];j++) cin>>x[j],tong[x[j]]++;
		for(long long j=2;j<=sz[i];j++) c[i].emplace_back(x[j]-x[j-1]),temp.push_back({x[j]-x[j-1],{x[j],i}}),len++;
	}
//	cout<<sum3+n<<'\n';
	cin>>zh;
	for(long long i=1;i<=n;i++) cin>>b[i];
	for(long long i=1;i<=n;i++) 
		for(auto x:c[i]) ans[++ans[0]]=x+1,ans[++ans[0]]=x;
	ans[++ans[0]]=1;
	sort(ans+1,ans+ans[0]+1);
	ans[0]=unique(ans+1,ans+ans[0]+1)-(ans+1);
	int id=0;
	for(long long i=1;i<=n;i++)
	{
		for(auto j:c[i]) 
		{
			int nw=fd(j);
			era2[nw].emplace_back(temp[id].second);
			era1[nw].emplace_back(i),id++;
		}
	}
	for(auto i:tong) sum1+=i.second*b[i.second];
	for(long long j=1;j<=ans[0];j++)
	{
		long long i=ans[j];
		long long tans=(sum3*i+sum2+i*n)*zh+sum1;
		res[++nw]={tans,i};
		for(auto j:era1[nw]) sum3--,sum2+=i;
		for(auto j:era2[nw])
		{
			int nw=tong[j.first];
			sum1-=nw*b[nw],tong[j.first]--,nw--;
			sum1+=nw*b[nw];
		}
	}
	sort(res+1,res+nw+1);
	long long sans=0,zans=res[1].first;
	for(long long i=1;i<=nw;i++)
	{
		if(res[i].first!=zans) break;
		sans++;
	}
	cout<<zans<<" "<<sans<<'\n';
	for(long long i=1;i<=sans;i++) cout<<res[i].second<<" ";
	return 0;
}
